//
//  NetWorkingTool.m
//  YiXiu
//
//  Created by yixiu on 16/7/24.
//  Copyright © 2016年 zzz. All rights reserved.
//

#import "NetWorkingTool.h"

@implementation NetWorkingTool




// @"users/addAndLogin"
+(void)POST:(NSString *)URLString parameters:(NSDictionary *)parameters success:(NetWorkingBlock)success failure:(NetWorkingBlock)failure{
    
    NSString * urlStr = [UrlHead stringByAppendingPathComponent:URLString];
    
    
    // 1.创建请求管理者
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] init];
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    [manager.requestSerializer setTimeoutInterval:10.0];
//    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    NSLog(@"urlStr:%@---parameter:%@",urlStr,parameters);
    [manager POST:urlStr parameters:parameters success:^(NSURLSessionDataTask *task, id responseObject) {
        
        success(responseObject,nil);
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        

        failure(nil,error);
    }];
}



+(void)GET:(NSString *)URLString parameters:(NSDictionary *)parameters success:(NetWorkingBlock)success failure:(NetWorkingBlock)failure{
    
    NSString * urlStr = [UrlHead stringByAppendingPathComponent:URLString];
    
    // 1.创建请求管理者
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] init];
    [manager.requestSerializer setTimeoutInterval:10.0];
    
    NSLog(@"URL:%@---parameter:%@",urlStr,parameters);
    [manager GET:urlStr parameters:parameters success:^(NSURLSessionDataTask *task, id responseObject) {
        
        success(responseObject,nil);
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        failure(nil,error);
    }];
}

+(void)GET:(NSString *)URLString success:(NetWorkingBlock)success failure:(NetWorkingBlock)failure{
    
    // 1.创建请求管理者
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] init];
    [manager.requestSerializer setTimeoutInterval:10.0];
    
//    NSLog(@"URL:%@---parameter:%@",urlStr,parameters);
    [manager GET:URLString parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        success(responseObject,nil);
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        failure(nil,error);
    }];
}



@end
